{extend name="base/form_base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
        <input type="hidden" name="token" value="{$token}" id='bb_token'>
        <input type="hidden" name="uid" value="{$uid}" id='uid'>
        <table id="table" lay-filter="table"></table> 
         <script type="text/html" id="barDemo">
          <a class="layui-btn layui-btn-xs" lay-event="edit">拨币</a>

        </script>
{/block}
{block name="script"}
<script>
layui.use('table', function(){
  var table = layui.table; 
  table.render({
  elem: '#table'
  ,id:'table'
  ,height: 'full-200'
  ,url: '/admin/user/balancelist?uid='+{$uid} //数据接口
  ,cols: [[ //表头
    {field:'wallet_name', title: '钱包', width: 200}
    ,{field:'address', title: '钱包地址', width: 400}
    ,{field:'balance', title: '可用余额', width: 200}
    // ,{field:'change',title: '拨币（可用余额）', width: 200, edit: 'text'}
     ,{title:'操作', toolbar: '#barDemo', width:200}
    ]]
  }); 

     //监听工具条
  table.on('tool(table)', function(obj){
    var data = obj.data;
    if(obj.event === 'edit'){
      layer.prompt({
      formType: 3,
        title: data.wallet_name+'：'+data.balance
      }, function(value,index){
        var post_data = {
          // id:data.id,
          field:'change',
          amount:value,
          'token':$('#bb_token').val(),
          'uid':$('#uid').val(),
          'wid':data.wid
        };
        $.ajax({
          url:'/admin/user/bb',
          type:'POST',
          data:post_data,
          success:function(ret){
            if (ret.code == 0) {
              layer.msg('修改成功');
              window.location.reload();
            } else {
              layer.msg(ret.msg);
            }
          }
        }); 
      });
    }
  }); 
  ///监听单元格编辑
 // table.on('edit(table)', function(obj){
 //    var value = obj.value //得到修改后的值
 //    ,data = obj.data //得到所在行所有键值
 //    ,field = obj.field; //得到字段
 //      layer.prompt({title: '请输入拨币密码', formType: 0}, function(password, index){
 //        var post_data ={
 //          'password':password,
 //          id:data.id,
 //          field:field,
 //          amount:value,
 //          'token':$('#bb_token').val()
 //        };
 //    $.ajax({
 //            url:"{:url('admin/user/bb')}",
 //            type:"POST",
 //            data:post_data,
 //            success:function(ret){
 //                if (ret.code == 1) {
 //                  layer.msg('操作成功');
 //                  window.location.reload();
 //                }
 //                if (ret.code == 0) {
 //                    layer.msg(ret.msg);
 //                }
 //            }
 //        });
 //    });
 //  });
});
  function cancel(){
    window.location.href=document.referrer;
  }
</script>
{/block}
